<?php
//  This file is part of EkkinCMS.
//
//  EkkinCMS is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  EkkinCMS is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with EkkinCMS.  If not, see <http://www.gnu.org/licenses/>.

function menu_get_children($id){
    global $db;
    $children = array();
    $r = $db->query("SELECT * FROM menu WHERE lang=\"en_US\"");
    foreach ($r as $key){
        if ($key[parent] == $id){
            $children[] = $key[id];
        }
    }
    return $children;
}

function menu_print($a, $level=-1){
    global $site_menus, $site_content, $menu_levels;
    $level ++;
    foreach ($a as $id){
        $site_content .= "{$site_menus[$id][0]} ($level)<br/>";
        $site_content .= "<blockquote>";
        $menu_levels[$id] = $level;
        $a2 = menu_get_children($id);
        menu_print($a2, $indent);
        $site_content .= "</blockquote>";

    }

}

$a = array();

foreach($site_menus as $id => $entry){
    $parent_id = menu_get_parent($id);
    if ( $parent_id == -1 ){
        $a[] = $id;
    }
}
//print_r($a);
menu_print($a);


?>
